import 'package:bruno/bruno.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:sph_driver/AppConfig/Config.dart';
import 'package:sph_driver/Main/CustomerService/ServiceProgress.dart';

import '../../AppConfig/RouteAct.dart';
import '../../l10n/messages.dart';

class InitiateComplaint extends StatefulWidget {
  const InitiateComplaint({super.key});

  @override
  State<InitiateComplaint> createState() => _InitiateComplaintState();
}

class _InitiateComplaintState extends State<InitiateComplaint> {
  int orderType=1;
  int timeChange=-1;
  String startTime="";
  String endTime="";
  String timeTitle="自选时间";
  List orderIDList=["1111111","22222222222","33333333333"];
  @override
  Widget build(BuildContext context) {
    final screenSize = MediaQuery.of(context).size;
    var messages = AppLocalizations.of(context)!;
    return Scaffold(
      backgroundColor: MyColors.backgreyColor,
      appBar: AppBar(
        backgroundColor:Colors.white,
        centerTitle: true,
        title: Text("运单选择",style: TextStyle(color: Colors.black,fontWeight: FontWeight.w300,fontSize: 16.sp),),
        actions: [
          TextButton(onPressed: (){
            Navigator.push( context, FadeRoute(page:ServiceProgress()));

          }, child: Text("投诉记录",style: TextStyle(color: Colors.black),)),
          ],
      ),
      body: ListView(
        physics: NeverScrollableScrollPhysics(),
        children: [
          Container(
            color: Colors.white,
            child:Row(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: [
                SizedBox(),
                GestureDetector(
                  child: Column(
                    children: [
                      Text("普通运单",style: TextStyle (fontWeight:orderType==1? FontWeight.w600:FontWeight.w300,color:orderType==1?MyColors.themeColor: Colors.black,fontSize: orderType==1?14.sp:14.sp),),
                      SizedBox(height: 8.h,),
                      Container(height: 2.h,width: 27.w,color:orderType==1?Color.fromRGBO(231, 112, 27, 0.85) : Colors.white.withOpacity(0.0),),
                    ],
                  ),
                  onTap: (){
                    setState(() {
                      orderType=1;
                    });
                  },
                ),
                SizedBox(),
                GestureDetector(
                  child: Column(
                    children: [
                      Text("分配单",style: TextStyle (fontWeight:orderType==2? FontWeight.w600:FontWeight.w300,color:orderType==2?MyColors.themeColor: Colors.black,fontSize: orderType==2?14.sp:14.sp),),
                      SizedBox(height: 8.h,),
                      Container(height: 2.h,width: 27.w,color:orderType==2?Color.fromRGBO(231, 112, 27, 0.85) : Colors.white.withOpacity(0.0),),
                    ],
                  ),
                  onTap: (){
                    setState(() {
                      orderType=2;
                    });
                  },
                ),
                SizedBox(),
              ],
            ),
          ),
          SizedBox(height: 1.h,),

          Container(
            color: Colors.white,
            child: Row(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: [
                BrnSmallMainButton(
                  title: '近1个月',
                  bgColor:timeChange ==1?Color.fromRGBO(231, 112, 27, 0.15): Colors.white,
                  textColor: timeChange==1?MyColors.themeColor: Colors.black,
                  fontWeight: FontWeight.w300,
                  fontSize: 13.sp,
                  width:screenSize.width/4,
                  onTap: () {
                    setState(() {
                      timeChange=1;
                    });

                  },
                ),
                BrnSmallMainButton(
                  title: '近3个月',
                  bgColor:timeChange ==2?Color.fromRGBO(231, 112, 27, 0.15):  Colors.white,
                  textColor: timeChange==2?MyColors.themeColor: Colors.black,
                  fontWeight: FontWeight.w300,
                  fontSize: 13.sp,
                  width:screenSize.width/4,
                  onTap: () {
                    setState(() {
                      timeChange=2;
                    });

                  },
                ),
                BrnSmallMainButton(
                  title: '近6个月',
                  bgColor:timeChange ==3?Color.fromRGBO(231, 112, 27, 0.15):  Colors.white,
                  textColor: timeChange==3?MyColors.themeColor: Colors.black,
                  fontWeight: FontWeight.w300,
                  fontSize: 13.sp,
                  width:screenSize.width/4,
                  onTap: () {
                    setState(() {
                      timeChange=3;
                    });

                  },
                ),
                BrnSmallMainButton(
                  title: timeTitle,
                  bgColor:timeChange ==4?Color.fromRGBO(231, 112, 27, 0.15):  Colors.white,
                  textColor: timeChange==4?MyColors.themeColor: Colors.black,
                  fontWeight: FontWeight.w300,
                  fontSize: startTime==""? 13.sp:11.sp,
                  width:screenSize.width/4,
                  onTap: () {
                    setState(() {
                      timeChange=4;
                    });
                    showModalBottomSheet(context: context, builder: (BuildContext context)
                    {
                      return Container(
                        height: 500.h,
                        decoration: BoxDecoration(
                          color: Colors.white,
                          borderRadius: BorderRadius.all(Radius.circular(10)),
                        ),
                        child:
                            Column(
                              children: [
                                SizedBox(height: 8.h,),
                                Row(
                                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                                  children: [
                                    SizedBox(width: 20.w,),
                                    Text("运单时间筛选",style: TextStyle(color: Colors.black,fontSize: 16.sp,fontWeight: FontWeight.w600,)),
                                    GestureDetector(
                                      child: Icon(Icons.close,color: MyColors.textColor,),
                                      onTap: (){
                                      Navigator.pop(context);
                                      },
                                    )
                                  ],
                                ),
                                SizedBox(height: 8.h,),
                                BrnCalendarView.range(
                                  displayMode: DisplayMode.month,
                                  minDate: DateTime.now(),
                                  maxDate: DateTime(2050),
                                  rangeDateChange: (rangeDate) {
                                    startTime =rangeDate.start.toString();
                                    endTime =rangeDate.end.toString();
                                    setState(() {
                                      timeTitle  =startTime.substring(5,10)+"至"+endTime.substring(5,10);
                                    });


                                    Navigator.pop(context);
                                    // BrnToast.show(
                                    //
                                    //     '开始时间： ${rangeDate.start} , 结束时间：${rangeDate.end}', context);
                                  },
                                ),
                              ],
                            ),

                      );
                    }
                    );
                  },
                ),
              ],
            ),
          ),
        SizedBox(height: 8.h,),

        Container(
          height: screenSize.height-180.h,
          margin: EdgeInsets.only(left: 10.w,right: 10.w,bottom: 8.h),
          child: ListView.separated(
            // physics: NeverScrollableScrollPhysics(),
            shrinkWrap:false,
            itemCount: orderIDList.length,
            separatorBuilder: (BuildContext context, int index) {
              // 定义item之间的分隔符
              return Divider(
                height: 8.0, // 设置分隔符高度
                color: MyColors.backgreyColor,
              );
            },
            itemBuilder: (BuildContext context, int index) {
              return Container(
                height: 205.h,
                decoration: BoxDecoration(
                  color: Colors.white,
                  borderRadius: BorderRadius.all(Radius.circular(10)),
                ),
                padding: EdgeInsets.all(10.w),
                child: Column(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: [
                    Text("111****5555",style: TextStyle(color: Colors.black),),
                    SizedBox(height: 8.h,),
                    Container(height: 1.h,color: MyColors.backgreyColor,),
                    SizedBox(height: 15.h,),
                    Row(
                      children: [
                        Text("物流路线",style: TextStyle(color: MyColors.textColor),),
                        SizedBox(width: 8.w,),
                        Text("苏州市吴中区-苏州市吴中区",style: TextStyle(color: Colors.black),),
                      ],
                    ),
                    SizedBox(height: 6.h,),
                    Row(
                      children: [
                        Text("对方姓名",style: TextStyle(color: MyColors.textColor),),
                        SizedBox(width: 8.w,),
                        Text("张**",style: TextStyle(color: Colors.black),),
                      ],
                    ),
                    SizedBox(height: 6.h,),
                    Row(
                      children: [
                        Text("运单编号",style: TextStyle(color: MyColors.textColor),),
                        SizedBox(width: 8.w,),
                        Text(orderIDList[index],style: TextStyle(color: Colors.black),),
                      ],
                    ),
                    SizedBox(height: 6.h,),
                    Row(
                      children: [
                        Text("运单状态",style: TextStyle(color: MyColors.textColor),),
                        SizedBox(width: 8.w,),
                        Text("已完成",style: TextStyle(color: Colors.black),),
                      ],
                    ),
                    SizedBox(height: 6.h,),
                    Row(
                      children: [
                        Text("运单时间",style: TextStyle(color: MyColors.textColor),),
                        SizedBox(width: 8.w,),
                        Text("2023-05-23 11:55:25",style: TextStyle(color: Colors.black),),
                      ],
                    ),
                    SizedBox(height: 8.h,),
                    Row(
                      mainAxisAlignment: MainAxisAlignment.end,
                      children: [
                        BrnSmallMainButton(
                          title: '发起投诉',
                          bgColor: MyColors.themeColor,
                          textColor: Colors.white,
                          radius: 30,
                          width: 80.w,
                          onTap: () {
                            BrnToast.show('录需求信息', context);
                          },
                        ),
                      ],
                    ),

                  ],
                ),
              );
            },
        ),
        ),

        ],
      ),
    );
  }
}
